package com.tsinghuabigdata.edu.ddmath.dialog;

import android.app.Dialog;
import android.content.Context;








import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.tsinghuabigdata.edu.ddmath.R;
import com.tsinghuabigdata.edu.ddmath.bean.Pickers;
import com.tsinghuabigdata.edu.ddmath.commons.newbieguide.ScreenUtils;
import com.tsinghuabigdata.edu.ddmath.util.DensityUtils;
import com.tsinghuabigdata.edu.ddmath.view.PickerScrollView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;



/**
 * 登录中对话框
 * Created by Administrator on 2016/12/16.
 */

public class SelectTimeDialog extends Dialog {

    private LayoutInflater             inflater;
    private Context                    mContext;

    private PickerScrollView pickerscrlllview; // 滚动选择器
    private List<Pickers>    list; // 滚动选择器数据

    TimeSelectListener mTimeSelectListener;
    /**
     * @param context
     */
    public SelectTimeDialog(Context context) {
        super(context, R.style.dialog);
        this.mContext = context;
        inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View root = inflater.inflate(R.layout.dialog_select_time, null);
        setContentView(root);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        dialogWindow.setGravity(Gravity.BOTTOM);
        int dis = DensityUtils.dp2px(context, 296);
//        //显示的坐标
//        lp.y = dis;
        lp.width = ScreenUtils.getScreenWidth(context);
        lp.height = dis;
        dialogWindow.setAttributes(lp);
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        // 设置window属性
//        lp = getWindow().getAttributes();
//        lp.gravity = Gravity.CENTER;
//        lp.dimAmount = 0; // 去背景遮盖
//        lp.alpha = 1.0f;
//        getWindow().setAttributes(lp);


        pickerscrlllview = (PickerScrollView) root.findViewById(R.id.pickerscrlllview);
        TextView tvCancel = (TextView) root.findViewById(R.id.tv_cancel);
        TextView tvSure = (TextView) root.findViewById(R.id.tv_sure);
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                Pickers pickers = pickerscrlllview.gePickers();
                mTimeSelectListener.select(pickers.getShowId());
            }
        });
        initData();
    }

    /**
     * 初始化数据
     */
    private void initData() {
        list = new ArrayList<Pickers>();
        for (int i = 1; i < 31; i++) {
            list.add(new Pickers(i+"分钟", i));
        }
        // 设置数据，默认选择第一条
        pickerscrlllview.setData(list);
        pickerscrlllview.setSelected(0);
    }

    public interface TimeSelectListener {
        void select(int time);
    }

    public void setTimeSelectListener(TimeSelectListener timeSelectListener) {
        mTimeSelectListener = timeSelectListener;
    }
}
